package com.t174.car.controller;

import com.t174.car.dao.GuestsAdvisoryDao;
import com.t174.car.entity.GuestsAdvisory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/Advisory")
@Scope
public class GuestsAdvisoryController {
    @Autowired
GuestsAdvisoryDao guestsAdvisoryDao;
    @RequestMapping("/chaxun")
    @ResponseBody
    public List<GuestsAdvisory> qreuy(){
    return  guestsAdvisoryDao.qruey();
}
    @RequestMapping("/addGuestsAdvisory")
    @ResponseBody
public  int add(GuestsAdvisory guestsAdvisory){
//        guestsAdvisory.setGuests(1);
        return  guestsAdvisoryDao.getguestsAdvisory(guestsAdvisory);
    }
    @RequestMapping("/delete")
    @ResponseBody
    public int del(String ids){
        String[] ss = ids.split("-");
        Integer[] myids = new Integer[ss.length] ;
        for(int i=0;i<ss.length;i++){
            System.out.println(ss[i]);
            myids[i] = Integer.parseInt(ss[i]) ;
        }
        return guestsAdvisoryDao.delguestsAdvisory(myids);
    }
    @RequestMapping("/getid")
    @ResponseBody
    public GuestsAdvisory getid(int id){
        return guestsAdvisoryDao.idguestsAdvisory(id);
    }

    @RequestMapping("/update")
    @ResponseBody
    public int updateGuests(GuestsAdvisory guestsAdvisory){
        return guestsAdvisoryDao.updateAdvisory(guestsAdvisory);
    }


    @RequestMapping("/getguests")
    @ResponseBody
    public List<GuestsAdvisory> getguests(){
        return  guestsAdvisoryDao.getguests();
    }
}
